<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>试卷管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/layuimoduls/lib/layui-v2.6.3/css/layui.css" media="all">
	<link rel="stylesheet" href="/layuimoduls/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索试题</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">关键字</label>
							<div class="layui-input-inline">
								<input type="text" name="username" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">试卷科目</label>
							<div class="layui-input-inline">
								<input type="text" name="sex" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">试卷id</label>
							<div class="layui-input-inline">
								<input type="text" name="city" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>


		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

		<script type="text/html" id="currentTableBar">
			<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
		</script>

	</div>
</div>
<script src="/layuimoduls/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script  th:inline="none">
	layui.use(['form', 'table'], function () {
		var $ = layui.jquery,
				form = layui.form,
				table = layui.table;

		table.render({
			elem: '#currentTableId',
			url: '/queryExam',
			method:'post',
			defaultToolbar: ['filter', 'exports', 'print', {
				title: '提示',
				layEvent: 'LAYTABLE_TIPS',
				icon: 'layui-icon-tips'
			}],
			cols: [[
				{type: "checkbox", },
				{field: 'testid', title: 'ID', sort: true},
				{field: 'testname',  title: '试卷名称'},
				{field: 'start_time',  title: '开始时间'},
				{field: 'end_time',  title: '结束时间'},
				{field: 'subjectname',  title: '科目'},
				{field: 'teachername',  title: '出题人'},
				{field: 'score',  title: '分值', sort: true},
				{title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
			]],
			limits: [10, 15, 20, 25, 50, 100],
			limit: 15,
			page: true,
			skin: 'line',
			//分页
			parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
				var result;
				console.log(this);
				console.log(JSON.stringify(res));
				if (this.page.curr) {
					result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
				} else {
					result = res.data.slice(0, this.limit);
				}
				return {
					"code": res.code, //解析接口状态
					"msg": res.msg, //解析提示文本
					"count": res.count, //解析数据长度
					"data": result //解析数据列表
				}
			}
		});

		// 监听搜索操作
		form.on('submit(data-search-btn)', function (data) {
			var result = JSON.stringify(data.field);
			layer.alert(result, {
				title: '最终的搜索信息'
			});

			//执行搜索重载
			table.reload('currentTableId', {
				page: {
					curr: 1
				}
				, where: {
					searchParams: result
				}
			}, 'data');

			return false;
		});
	});
</script>

</body>
</html>